﻿using Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class UserService : IDisposable
    {
        public ApplicationDbService<ApplicationDbContext> DBService { get; set; }
        public UserService()
        {
            DBService = new ApplicationDbService<ApplicationDbContext>(new ApplicationDbContext());
        }

        public bool AddUser(UserEntity userInfo)
        {
            return DBService.Add<UserEntity>(userInfo) > 0;
        }

        public bool DeleteUser(string userId)
        {
            return DBService.Delete<UserEntity>(m=>m.Id == userId) > 0;
        }

        public bool UpdateUser(UserEntity userInfo)
        {
            return DBService.Update<UserEntity>(userInfo) > 0;
        }

        public IList<UserEntity> GetUserList()
        {
            return DBService.GetAll<UserEntity>().ToList();
        }

        public virtual void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing && this.DBService != null)
            {
                this.DBService.Dispose();
            }
        }
    }
}
